package com.cetccloud.ap.proxy.channel.cossDomain.s30.handler.recv;

import com.alibaba.fastjson.JSON;
import com.cetccloud.ap.proxy.channel.cossDomain.s30.channel.recv.S30RecvChannel;
import com.thunisoft.exchange.gateway.protocol.channel.GatewayChannelMessageType;
import com.thunisoft.exchange.gateway.protocol.channel.GatewayEntityMessage;
import com.thunisoft.exchange.gateway.protocol.channel.GatewayMetadataResponseMessage;
import com.thunisoft.exchange.gateway.protocol.entity.GatewayExchangeNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * @ClassName MetaRespHandler
 * @Description 名录请求回应
 * @Author superz
 * @Date 2021/4/22 20:47
 * @Version 1.0
 **/
@Slf4j
@Component
public class MetaRespHandler implements RecvChannelHandler<GatewayEntityMessage> {

    @Autowired
    private S30RecvChannel s30RecvChannel;

    @Override
    public GatewayChannelMessageType type() {
        return GatewayChannelMessageType.metaResp;
    }

    @Override
    public void handle(GatewayEntityMessage entityMessage) {
        log.info("主动请求名录数据响应... 数据: {}", JSON.toJSONString(entityMessage));
        ArrayList<GatewayExchangeNode> exchangeNodes =  ((GatewayMetadataResponseMessage) entityMessage.getEntity()).getMeta();
        s30RecvChannel.setExchangeNodes(exchangeNodes);
    }
}
